package com.sd.h3.carrental.bean.impl;

import com.sd.h3.carrental.bean.intf.LoginRemote;
import com.sd.h3.carrental.entity.LoginEntity;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.naming.InitialContext;
import javax.naming.NamingException;

@Stateless
public class LoginSession implements LoginRemote {

    

    @javax.persistence.PersistenceContext
    EntityManager em;

    public int login(String username, String pass) {

        Query query = em.createNamedQuery("findbyUserandPass");
        query.setParameter("username", username);
        query.setParameter("pass", pass);
        LoginEntity login = (LoginEntity)query.getSingleResult();
        if (login != null){
            if (login.getIsAdmin() == 1)
                return 1;
            else
                return 2;
        }
        return 3;
    }
}
